package com.guxingke.gblog.controller.front;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.guxingke.gblog.controller.BaseController;

@Controller
@RequestMapping("/category")
public class CategoryController extends BaseController {

	@RequestMapping
	public ModelAndView list() {
		ModelAndView mav = new ModelAndView();
		mav.addObject("categories", categoryService.getCategories());
		mav.addObject("mainPage", "category/list.jsp");
		mav.setViewName("home");
		return mav;
	}

	@RequestMapping("/detail")
	public ModelAndView get(@RequestParam(value = "categoryId", required = true) Integer id) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("category", categoryService.getCategory(id));
		mav.addObject("articles", articleService.getArticlesByCategory(id));
		mav.addObject("mainPage", "category/detail.jsp");
		mav.setViewName("home");
		return mav;
	}

	@RequestMapping("/about")
	public ModelAndView about() {
		ModelAndView mav = new ModelAndView();
		mav.addObject("about", articleService.getAbout());
		mav.addObject("mainPage", "about/detail.jsp");
		mav.setViewName("home");
		return mav;
	}
}
